package com.nuatar.meibi;

import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;

public class BootReceiver extends BroadcastReceiver {
	@Override
	public void onReceive(Context context, Intent intents) {
		SharedPreferences pre = PreferenceManager
				.getDefaultSharedPreferences(context.getApplicationContext());
		String vc = pre.getString("UpdateQue", "0");
		int iq;
		if (!vc.equals("0")) {
			iq = Integer.parseInt(vc);
		} else {
			iq = 10;
		}
		if (iq > 0) {
			AlarmManager alarmMgr = (AlarmManager) context
					.getSystemService(Context.ALARM_SERVICE);
			Intent intent = new Intent(context.getApplicationContext(),
					AlarmReceiver.class);
			int requestCode = 0;
			PendingIntent pendIntent = PendingIntent.getBroadcast(
					context.getApplicationContext(), requestCode, intent,
					PendingIntent.FLAG_UPDATE_CURRENT);
			int interval = 60 * 1000 * iq;
			alarmMgr.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, 120000,
					interval, pendIntent);
		}
		AlarmManager alarmMgr = (AlarmManager) context
				.getSystemService(Context.ALARM_SERVICE);
		Intent intent = new Intent(context.getApplicationContext(),
				MsgAlarmReceiver.class);
		int requestCode = 0;
		PendingIntent pendIntent = PendingIntent.getBroadcast(
				context.getApplicationContext(), requestCode, intent,
				PendingIntent.FLAG_UPDATE_CURRENT);
		int interval = 60 * 1000;
		alarmMgr.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, 5000,
				interval, pendIntent);

	}

}